﻿#if UMB45
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using umbraco.editorControls.tags;
using umbraco.interfaces;
using umbraco.presentation;

namespace umbraco.blog4.DataTypes.GroupedTags {
    public class DataType : umbraco.editorControls.tags.DataType, IDataType {
    
        #region IDataType Members
        private IDataEditor _Editor;

        public override IDataEditor DataEditor {
            get {
                if (_Editor == null) {
                    var preValues = ((umbraco.editorControls.tags.PrevalueEditor)PrevalueEditor).Prevalues;
                    if (UmbracoContext.Current.PageId.HasValue) {
                        string category = (string)BlogLibrary.GetValueRecursively("category", UmbracoContext.Current.PageId.Value);
                        if (!string.IsNullOrEmpty(category)) {
                            if (preValues["group"] == null || (string)preValues["group"] == "default")
                            preValues["group"] = category;
                        }
                    }
                    _Editor = new umbraco.editorControls.tags.DataEditor(Data, preValues);
                }
                return _Editor;
            }
        }

        public override string DataTypeName { get { return "Blog Tags"; } }
        public override Guid Id {
            get {
                return new Guid("BD8B240F-0DE3-47E5-A172-2DE212CC30B6"); 
                // this was the core umbraco tags datatype GUID.
                //get { return new Guid("4023e540-92f5-11dd-ad8b-0800200c9a66"); }
            }
        }
        #endregion
    }
}
#endif